package com.asm.controller.api;

import com.asm.controller.BaseController;
import com.asm.dto.PageResult;
import com.asm.dto.Result;
import com.asm.service.TradeAreaService;
import com.asm.vo.sys.TradeAreaVo;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 商圈接口
 *
 * @author morningbear
 */
@Slf4j
@RestController
@Api(value = "商圈Controller")
public class TradeAreaController extends BaseController {

    @Resource
    private TradeAreaService tradeAreaService;

    @ApiOperation("接口描述：获取所有的商圈")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNumber", value = "页数"),
            @ApiImplicitParam(name = "pageSize", value = "页面大小")
    })
    @GetMapping("/tradeareas")
    public ResponseEntity<PageResult<TradeAreaVo>> getAllTradeArea(@RequestParam(value = "pageNumber", defaultValue = "0") Integer pageNumber, @RequestParam(value = "pageSize", defaultValue = "1000") Integer pageSize) {
        return new ResponseEntity(new Result().ok("success", tradeAreaService.findAllTradeAreas(pageNumber, pageSize)), HttpStatus.OK);
    }

    @ApiOperation("接口描述：增加商圈")
    @PostMapping("/tradearea/add")
    public ResponseEntity<Result> addTradeArea(@RequestBody @ApiParam(name = "tradeAreaVo", value = "商圈视图对象") TradeAreaVo tradeAreaVo) {
        tradeAreaService.addTradeArea(tradeAreaVo);
        return new ResponseEntity(new Result().ok("add success"), HttpStatus.OK);
    }

    @ApiOperation("接口描述：删除商圈")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "商圈编号"),
    })
    @DeleteMapping("/tradearea/{id}")
    public ResponseEntity<Result> deleteTradeArea(@PathVariable("id") Long id) {
        tradeAreaService.deleteTradeArea(id);
        return new ResponseEntity(new Result().ok("delete success"), HttpStatus.OK);
    }

    @ApiOperation("接口描述：更新商圈")
    @PutMapping("/tradearea/update")
    public ResponseEntity<Result> updateTradeArea(@RequestBody @ApiParam(name = "tradeAreaVo", value = "商圈视图对象") TradeAreaVo tradeAreaVo) {
        tradeAreaService.updateTradeArea(tradeAreaVo);
        return new ResponseEntity(new Result().ok("update success"), HttpStatus.OK);
    }
}
